// src/renderer/models/validators/SerialPortValidator.ts
import type { OpenSerialRequest } from '../up_request';

export class SerialPortValidator {
  // 常见波特率和特殊波特率合并为静态属性，便于维护
  private static readonly COMMON_BAUDRATES = [
    300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200,
    230400, 460800, 921600, 1000000, 2000000,
  ];

  static isValidBaudrate(baudrate: number): boolean {
    return SerialPortValidator.COMMON_BAUDRATES.includes(baudrate);
  }

  static validateForm(data: OpenSerialRequest): {
    isValid: boolean;
    message?: string;
  } {
    if (!this.isValidBaudrate(data.baudrate)) {
      return { isValid: false, message: '波特率不支持，请选择常用波特率' };
    }
    // 可扩展更多字段校验
    return { isValid: true };
  }
}

export default SerialPortValidator;
